package cn.jee.controller;

import cn.jee.entity.Teacher;
import cn.jee.repository.TeacherRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class TeacherController {

  @Autowired
  TeacherRepository teacherRepository;

  @RequestMapping("/")
  public String listTeachers(Model model) {
    List<Teacher> teachers = teacherRepository.findAll();
    model.addAttribute("teachers", teachers);
    return "index";
  }

  @RequestMapping("/Teacher_input")
  public String TeacherInput() {
    return "addTeacher";
  }
  @RequestMapping("/addTeacher")
  public String addTeacher(Teacher teacher) {
    teacherRepository.save(teacher);
    return "redirect:/";
  }
}

